package fr.androguies.powerball;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.primitive.Line;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import com.googlecode.androidannotations.annotations.EActivity;

import fr.androguies.powerball.scene.SceneJeu;

@EActivity
public class CopyOfPowerBallActivity extends BaseGameActivity {

	private static final int CAMERA_WIDTH = 480;
	private static final int CAMERA_HEIGHT = 320;
	
	private Camera camera;
	private SceneJeu myScene;
	private TextureRegion regionImage;
	private Texture textureSoldier;
	private TiledTextureRegion soldier;
	
	
	public CopyOfPowerBallActivity() {
		
	}
	
	@Override
	public Engine onLoadEngine() {
		camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		myScene = new SceneJeu(this);
		
		final RatioResolutionPolicy resolutionPolicy = new RatioResolutionPolicy(camera.getWidth(), camera.getHeight());
		final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, resolutionPolicy, camera);
		return new Engine(engineOptions);
	}

	@Override
	public void onLoadResources() {
		TextureRegionFactory.setAssetBasePath("gfx/");
		
		myScene.loadResources();
		
		final Texture textureImage = new Texture(64, 64,TextureOptions.BILINEAR);
		regionImage = TextureRegionFactory.createFromAsset(textureImage, this, "andengine.png", 0, 0);
		getEngine().getTextureManager().loadTexture(textureImage);
		
		textureSoldier = new Texture(512, 64);
		
		soldier = TextureRegionFactory.createTiledFromAsset(textureSoldier, this, "soldier.png", 0, 0, 8, 1);
		getEngine().getTextureManager().loadTextures(textureSoldier);
	}

	@Override
	public Scene onLoadScene() {
		final Rectangle rectangle = new Rectangle(camera.getWidth()/2, camera.getHeight()/2, 100, 50);
		rectangle.setColor(0, 0, 255);
		
		final Line line = new Line(0, 0, camera.getWidth(), camera.getHeight());
		line.setColor(0.5f, 0.5f, 0.5f);
		
		final Sprite sprite = new Sprite(50, 50, regionImage);
		
		final AnimatedSprite animatedSprite = new AnimatedSprite(50, 100, soldier);
		animatedSprite.animate(25, true);
		
		myScene.attachChild(rectangle);
		myScene.attachChild(line);
		myScene.attachChild(sprite);
		myScene.attachChild(animatedSprite);
		
		return myScene;
	}

	@Override
	public void onLoadComplete() {
		// TODO Auto-generated method stub
		
	}
    
}